package cn.bj.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
/*
 * 初次访问就要把各类信息装载
 * 
 * */
import org.springframework.web.bind.annotation.RequestMapping;

import cn.bj.beans.Advertisement_picture;
import cn.bj.beans.Rotate;
import cn.bj.beans.Yxfw_candy;
import cn.bj.beans.Yxfw_candy_rotate;
import cn.bj.beans.Yxfw_car;
import cn.bj.beans.Yxfw_car_rotate;
import cn.bj.beans.Yxfw_jewellery;
import cn.bj.beans.Yxfw_jewellery_rotate;
import cn.bj.beans.Yxfw_man;
import cn.bj.beans.Yxfw_man_rotate;
import cn.bj.beans.Yxfw_travel;
import cn.bj.beans.Yxfw_travel_rotate;
import cn.bj.beans.Yxfw_wine;
import cn.bj.beans.Yxfw_wine_rotate;
import cn.bj.beans.Yxhq;
import cn.bj.beans.Yxhq_work_picture;
import cn.bj.beans.Yxhz;
import cn.bj.beans.Yxhz_work_picture;
import cn.bj.beans.Yxjd;
import cn.bj.beans.Yxjd_rotate;
import cn.bj.beans.Yxsx;
import cn.bj.beans.Yxsy;
import cn.bj.beans.Yxsy_work_picture;
import cn.bj.beans.Yxzc;
import cn.bj.beans.Yxzc_work_picture;
import cn.bj.service.AdvertisementService;
import cn.bj.service.CandyRotateService;
import cn.bj.service.CandyService;
import cn.bj.service.CarRotateService;
import cn.bj.service.CarService;
import cn.bj.service.JewelleryRotateService;
import cn.bj.service.JewelleryService;
import cn.bj.service.ManRotateService;
import cn.bj.service.ManService;
import cn.bj.service.RotateService;
import cn.bj.service.TravelRotateService;
import cn.bj.service.TravelService;
import cn.bj.service.Userservice;
import cn.bj.service.WineRotateService;
import cn.bj.service.WineService;
import cn.bj.service.YxhqService;
import cn.bj.service.YxhqWorkPictureService;
import cn.bj.service.YxhzService;
import cn.bj.service.YxhzWorkPictureService;
import cn.bj.service.YxjdRotateService;
import cn.bj.service.YxjdService;
import cn.bj.service.YxsxService;
import cn.bj.service.YxsyService;
import cn.bj.service.YxsyWorkPictureService;
import cn.bj.service.YxzcService;
import cn.bj.service.YxzcWorkPictureService;

/*
 * 首页的请求
 * 
 * */
@Controller
public class IndexController {
	@Autowired
	RotateService rotateService;

	@Autowired
	YxhqService yxhqService;

	@Autowired
	YxhqWorkPictureService yxhqWorkPictureService;

	@Autowired
	AdvertisementService advertisementSservice;

	@Autowired
	YxjdService yxjdService;

	@Autowired
	YxjdRotateService yxjdRotateService;

	@Autowired
	YxzcService yxzcService;

	@Autowired
	YxzcWorkPictureService yxzcWorkPictureService;

	@Autowired
	YxsxService yxsxService;

	@Autowired
	YxhzService yxhzService;

	@Autowired
	YxhzWorkPictureService yxhzWorkPictureService;

	@Autowired
	YxsyService yxsyService;

	@Autowired
	YxsyWorkPictureService yxsyWorkPictureService;

	@Autowired
	CandyService candyService;

	@Autowired
	CandyRotateService candyRotateService;

	@Autowired
	CarService carService;

	@Autowired
	CarRotateService carRotateService;

	@Autowired
	ManService manService;

	@Autowired
	ManRotateService manRotateService;

	@Autowired
	JewelleryService jewelleryService;

	@Autowired
	JewelleryRotateService jewelleryRotateService;

	@Autowired
	TravelService travelService;

	@Autowired
	TravelRotateService travelRotateService;

	@Autowired
	WineService wineService;

	@Autowired
	WineRotateService wineRotateService;

	@Autowired
	Userservice userService;

	// 首页请求
	@RequestMapping("/")
	public String firstRequest(HttpSession session) {
		// 2放入首页轮播图
		List<Rotate> rotates = rotateService.getAllRotats();
		session.setAttribute("rotates", rotates);

		// 3放入优选婚庆
		List<Yxhq> allYxhqs = yxhqService.getAllYxhq();
		session.setAttribute("allYxhqs", allYxhqs);

		// 4放入优选婚庆工作集
		/*
		 * List<Yxhq_work_picture> yxhqWPs =
		 * yxhqWorkPictureService.getAllYxhqWorkPicture();
		 * session.setAttribute("yxhqWPs", yxhqWPs);
		 */

		// 5.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		session.setAttribute("advers", advers);

		// 6.放入优选酒店
		List<Yxjd> yxjds = yxjdService.selectAllYxjd();
		session.setAttribute("yxjds", yxjds);

		// 7.放入酒店的轮播图
		/*
		 * List<Yxjd_rotate> yxjdRs = yxjdRotateService.selectAllYxjdRotate();
		 * session.setAttribute("yxjdRs", yxjdRs);
		 */

		// 8.放入主持人
		List<Yxzc> yxzcs = yxzcService.selcectAllYxzc();
		session.setAttribute("yxzcs", yxzcs);

		// 9.放入主持人作品集
		/*
		 * List<Yxzc_work_picture> yxzcWPs =
		 * yxzcWorkPictureService.getAllYxhqWorkPicture();
		 * session.setAttribute("yxzcWPs", yxzcWPs);
		 */

		// 10.放入优选摄像
		List<Yxsx> yxsxs = yxsxService.getAllYxhqWorkPicture();
		session.setAttribute("yxsxs", yxsxs);

		// 11.放入优选化妆
		List<Yxhz> yxhzs = yxhzService.getAllYxhz();
		session.setAttribute("yxhzs", yxhzs);

		// 12.放入化妆师作品集
		/*
		 * List<Yxhz_work_picture> yxhzWPs =
		 * yxhzWorkPictureService.getAllYxhzWorkPicture();
		 * session.setAttribute("yxhzWPs", yxhzWPs);
		 */

		// 13.放入优选摄影
		List<Yxsy> yxsys = yxsyService.getAllYxhz();
		session.setAttribute("yxsys", yxsys);

		// 14.放入摄影师作品集
		/*
		 * List<Yxsy_work_picture> yxsyWPs =
		 * yxsyWorkPictureService.getAllYxsyWorkPicture();
		 * session.setAttribute("yxsyWPs", yxsyWPs);
		 */

		// 15.放入服务糖果
		List<Yxfw_candy> candys = candyService.getAllCandys();
		session.setAttribute("candys", candys);

		// 16.放入服务糖果的轮播图
		/*
		 * List<Yxfw_candy_rotate> candyRs =
		 * candyRotateService.selectAllCandyRotate();
		 * session.setAttribute("candyRs", candyRs);
		 */

		// 17.放入服务汽车
		List<Yxfw_car> cars = carService.getAllCandys();
		session.setAttribute("cars", cars);

		// 18.放入服务汽车的轮播图
		/*
		 * List<Yxfw_car_rotate> carRs = carRotateService.selectAllCarRotate();
		 * session.setAttribute("carRs", carRs);
		 */

		// 19.放入服务男装
		List<Yxfw_man> mans = manService.getAllCandys();
		session.setAttribute("mans", mans);

		// 20.放入服务男装的轮播图
		/*
		 * List<Yxfw_man_rotate> manRs = manRotateService.selectAllCarRotate();
		 * session.setAttribute("manRs", manRs);
		 */

		// 21.放入优选珠宝
		List<Yxfw_jewellery> jewes = jewelleryService.getAllCandys();
		session.setAttribute("jewes", jewes);

		// 22.放入珠宝轮播图
		/*
		 * List<Yxfw_jewellery_rotate> jeweRs =
		 * jewelleryRotateService.selectAllJeweRotate();
		 * session.setAttribute("jeweRs", jeweRs);
		 */

		// 23.放入优选旅行
		List<Yxfw_travel> travels = travelService.getAllTravels();
		session.setAttribute("travels", travels);

		// 24.放入旅行轮播图
		/*
		 * List<Yxfw_travel_rotate> travelRs =
		 * travelRotateService.selectAllTravelRotate();
		 * session.setAttribute("travelRs", travelRs);
		 */

		// 25.放入服务酒水
		List<Yxfw_wine> wines = wineService.getAllWines();
		session.setAttribute("wines", wines);

		// 26.放入服务酒水轮播图
		/*
		 * List<Yxfw_wine_rotate> wineRs =
		 * wineRotateService.selectAllWineRotate();
		 * session.setAttribute("wineRs", wineRs);
		 */
		return "user/index";
	}

	// 婚庆详情页视频
	@RequestMapping("/user/yxhq/{id}.go")
	public String toYxhqDetails(@PathVariable("id") int id, HttpServletRequest request) {
		System.out.println(id);

		// 获取到id的值
		int ids = id;
		int idx1 = (ids - 1) * 5;// 左侧开始与结束位置
		int idx2 = (ids * 5) - 4;// 右侧开始位置
		int idx3 = (ids * 5) - 1;// 右侧结束位置

		request.setAttribute("id", id);
		request.setAttribute("idx1", idx1);
		request.setAttribute("idx2", idx2);
		request.setAttribute("idx3", idx3);

		// 3放入优选婚庆
		Yxhq yxhq = yxhqService.selectById(id);
		request.setAttribute("yxhq", yxhq);

		// 4放入优选婚庆工作集
		List<Yxhq_work_picture> yxhqWPs = yxhqWorkPictureService.getAllYxhqWorkPicture();
		request.setAttribute("yxhqWPs", yxhqWPs);

		return "user/wed-detail";
	}

	// 酒店详情页
	@RequestMapping("/user/yxjd/{id}.go")
	public String toYxjdDetails(@PathVariable("id") Integer id, HttpServletRequest request) {
		// 获取到id的值
		int ids = id;
		int idx1 = (ids - 1) * 7;// 轮播图开始位置
		int idx3 = (ids * 7) - 1;// 轮播图结束位置

		// 设值到页面
		request.setAttribute("id", id);
		request.setAttribute("idx1", idx1);
		request.setAttribute("idx3", idx3);

		// 6.放入单个优选酒店
		Yxjd yxjd = yxjdService.selectById(id);
		request.setAttribute("yxjd", yxjd);

		// 7.放入酒店的轮播图
		List<Yxjd_rotate> yxjdRs = yxjdRotateService.selectAllYxjdRotate();
		request.setAttribute("yxjdRs", yxjdRs);

		return "user/hotel-detail";
	}

	// 主持人详情页视频
	@RequestMapping("/user/yxzc/{id}.go")
	public String toYxzcDetails(@PathVariable("id") Integer id, HttpServletRequest request) {
		// 获取到id的值
		int ids = id;

		int idx = (ids - 1) * 6;// 左上开始与结束位置
		System.out.println(idx);
		int idx1 = (ids * 6) - 5;// 左下开始与结束位置
		System.out.println(idx1);

		int idx2 = (ids * 6) - 4;// 右侧开始位置
		System.out.println(idx2);
		int idx3 = (ids * 6) - 1;// 右侧结束位置
		System.out.println(idx3);

		// 设值到页面
		request.setAttribute("id", id);
		request.setAttribute("idx", idx);
		request.setAttribute("idx1", idx1);
		request.setAttribute("idx2", idx2);
		request.setAttribute("idx3", idx3);

		// 6.放入单个优选主持
		Yxzc yxzc = yxzcService.selectById(id);
		request.setAttribute("yxzc", yxzc);
		// 主持作品集
		List<Yxzc_work_picture> yxzcWPs = yxzcWorkPictureService.getAllYxhqWorkPicture();
		request.setAttribute("yxzcWPs", yxzcWPs);

		return "user/host-detail";
	}

	// 化妆详情页
	@RequestMapping("/user/yxhz/{id}.go")
	public String toYxhzDetails(@PathVariable("id") int id, HttpServletRequest request) {
		System.out.println(id);

		// 获取到id的值
		int ids = id;
		int idx1 = (ids - 1) * 5;// 左侧开始与结束位置
		int idx2 = (ids * 5) - 4;// 右侧开始位置
		int idx3 = (ids * 5) - 1;// 右侧结束位置

		request.setAttribute("id", id);
		request.setAttribute("idx1", idx1);
		request.setAttribute("idx2", idx2);
		request.setAttribute("idx3", idx3);

		// 11.放入优选化妆
		Yxhz yxhz = yxhzService.selectById(id);
		request.setAttribute("yxhz", yxhz);

		// 12.放入化妆师作品集
		List<Yxhz_work_picture> yxhzWPs = yxhzWorkPictureService.getAllYxhzWorkPicture();
		request.setAttribute("yxhzWPs", yxhzWPs);

		return "user/paint-detail";
	}

	// 优选摄像
	@RequestMapping("/user/yxsx/{id}.go")
	public String toYxsxDetails(@PathVariable("id") int id, HttpServletRequest request) {
		System.out.println(id);

		// 获取到id的值
		int ids = id;
		int idx2 = (ids - 1) * 2;// 视频开始位置
		int idx3 = (ids * 2) - 1;// 视频结束位置

		request.setAttribute("id", id);
		request.setAttribute("idx2", idx2);
		request.setAttribute("idx3", idx3);

		// 11.放入优选摄像,两个小视频对应数据表p1/p2字段
		Yxsx yxsx = yxsxService.selectById(id);
		request.setAttribute("yxsx", yxsx);

		return "user/video-detail";
	}

	// 摄影详情页
	@RequestMapping("/user/yxsy/{id}.go")
	public String toYxsyDetails(@PathVariable("id") int id, HttpServletRequest request) {
		System.out.println(id);

		// 获取到id的值
		int ids = id;
		int idx1 = (ids - 1) * 5;// 左侧开始与结束位置
		int idx2 = (ids * 5) - 4;// 右侧开始位置
		int idx3 = (ids * 5) - 1;// 右侧结束位置

		request.setAttribute("id", id);
		request.setAttribute("idx1", idx1);
		request.setAttribute("idx2", idx2);
		request.setAttribute("idx3", idx3);

		// 13.放入优选摄影
		Yxsy yxsy = yxsyService.selectById(id);
		request.setAttribute("yxsy", yxsy);

		// 14.放入摄影师作品集
		List<Yxsy_work_picture> yxsyWPs = yxsyWorkPictureService.getAllYxsyWorkPicture();
		request.setAttribute("yxsyWPs", yxsyWPs);

		return "user/photo-detail";
	}

	// 糖果详情页
	@RequestMapping("/user/candy/{id}.go")
	public String toCandyDetails(@PathVariable("id") Integer id, HttpServletRequest request) {

		// 设值到页面
		request.setAttribute("id", id);

		// 15.放入服务糖果
		Yxfw_candy candy = candyService.selectById(id);
		request.setAttribute("candy", candy);

		// 16.放入服务糖果的轮播图
		List<Yxfw_candy_rotate> candyRs = candyRotateService.selectAllCandyRotate();
		request.setAttribute("candyRs", candyRs);

		return "user/candy-detail";
	}

	// 汽车详情页
	@RequestMapping("/user/car/{id}.go")
	public String toCarDetails(@PathVariable("id") Integer id, HttpServletRequest request) {

		// 设值到页面
		request.setAttribute("id", id);

		// 15.放入服务汽车
		Yxfw_car car = carService.selectById(id);
		request.setAttribute("car", car);

		// 16.放入服务汽车的轮播图
		List<Yxfw_car_rotate> carRs = carRotateService.selectAllCarRotate();
		request.setAttribute("carRs", carRs);

		return "user/car-detail";
	}

	// 男装详情页
	@RequestMapping("/user/man/{id}.go")
	public String toManDetails(@PathVariable("id") Integer id, HttpServletRequest request) {

		// 设值到页面
		request.setAttribute("id", id);

		// 15.放入服务男装
		Yxfw_man man = manService.selectById(id);
		request.setAttribute("man", man);

		// 16.放入服务男装的轮播图
		List<Yxfw_man_rotate> manRs = manRotateService.selectAllCarRotate();
		request.setAttribute("manRs", manRs);

		return "user/man-detail";
	}

	// 珠宝详情页
	@RequestMapping("/user/jewel/{id}.go")
	public String toJewelDetails(@PathVariable("id") Integer id, HttpServletRequest request) {

		// 设值到页面
		request.setAttribute("id", id);

		// 21.放入优选珠宝
		Yxfw_jewellery jewel = jewelleryService.selectById(id);
		request.setAttribute("jewel", jewel);

		// 22.放入珠宝轮播图
		List<Yxfw_jewellery_rotate> jeweRs = jewelleryRotateService.selectAllJeweRotate();
		request.setAttribute("jeweRs", jeweRs);

		return "user/jewel-detail";
	}

	// 旅行详情页
	@RequestMapping("/user/trave/{id}.go")
	public String toTravelDetails(@PathVariable("id") Integer id, HttpServletRequest request) {

		// 设值到页面
		request.setAttribute("id", id);

		// 23.放入优选旅行
		Yxfw_travel travel = travelService.selectById(id);
		request.setAttribute("travel", travel);

		// 24.放入旅行轮播图
		List<Yxfw_travel_rotate> travelRs = travelRotateService.selectAllTravelRotate();
		request.setAttribute("travelRs", travelRs);

		return "user/travel-detail";
	}

	// 酒水详情页
	@RequestMapping("/user/wine/{id}.go")
	public String toWineDetails(@PathVariable("id") Integer id, HttpServletRequest request) {

		// 设值到页面
		request.setAttribute("id", id);

		// 15.放入服务酒水
		Yxfw_wine wine = wineService.selectById(id);
		request.setAttribute("wine", wine);

		// 16.放入服务酒水的轮播图
		List<Yxfw_wine_rotate> wineRs = wineRotateService.selectAllWineRotate();
		request.setAttribute("wineRs", wineRs);

		return "user/drinks-detail";
	}

	// 酒水详情页
	@RequestMapping("/user/service/list.go")
	public String toServiceList(HttpServletRequest request) {
		// 1.放入服务糖果的轮播图
		List<Yxfw_candy_rotate> candyRs = candyRotateService.selectAllCandyRotate();
		request.setAttribute("candyRs", candyRs);

		// 2.放入服务汽车的轮播图
		List<Yxfw_car_rotate> carRs = carRotateService.selectAllCarRotate();
		request.setAttribute("carRs", carRs);

		// 3.放入服务男装的轮播图
		List<Yxfw_man_rotate> manRs = manRotateService.selectAllCarRotate();
		request.setAttribute("manRs", manRs);

		// 4.放入珠宝轮播图
		List<Yxfw_jewellery_rotate> jeweRs = jewelleryRotateService.selectAllJeweRotate();
		request.setAttribute("jeweRs", jeweRs);

		// 5.放入旅行轮播图
		List<Yxfw_travel_rotate> travelRs = travelRotateService.selectAllTravelRotate();
		request.setAttribute("travelRs", travelRs);

		// 6.放入服务酒水的轮播图
		List<Yxfw_wine_rotate> wineRs = wineRotateService.selectAllWineRotate();
		request.setAttribute("wineRs", wineRs);

		return "user/server-list";
	}

	// 优选婚庆集合列表页
	@RequestMapping("/user/yxhq/list.go")
	public String toYxhqList(HttpServletRequest request) {

		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 2.放入优选婚庆
		List<Yxhq> allYxhqs = yxhqService.getAllYxhq();
		request.setAttribute("allYxhqs", allYxhqs);

		return "user/wed-list";
	}

	// 优选酒店集合列表页
	@RequestMapping("/user/yxjd/list.go")
	public String toYxjdList(HttpServletRequest request) {

		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 2.放入优选酒店
		List<Yxjd> yxjds = yxjdService.selectAllYxjd();
		request.setAttribute("yxjds", yxjds);

		return "user/hotel-list";
	}

	// 优选主持集合列表页
	@RequestMapping("/user/yxzc/list.go")
	public String toYxzcList(HttpServletRequest request) {
		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 8.放入主持人
		List<Yxzc> yxzcs = yxzcService.selcectAllYxzc();
		request.setAttribute("yxzcs", yxzcs);

		return "user/host-list";
	}

	// 优选化妆集合列表页
	@RequestMapping("/user/yxhz/list.go")
	public String toYxhzList(HttpServletRequest request) {
		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 11.放入优选化妆
		List<Yxhz> yxhzs = yxhzService.getAllYxhz();
		request.setAttribute("yxhzs", yxhzs);

		return "user/paint-list";
	}

	// 优选摄像集合列表页
	@RequestMapping("/user/yxsx/list.go")
	public String toYxsxList(HttpServletRequest request) {
		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 10.放入优选摄像
		List<Yxsx> yxsxs = yxsxService.getAllYxhqWorkPicture();
		request.setAttribute("yxsxs", yxsxs);

		return "user/video-list";
	}

	// 优选摄影集合列表页
	@RequestMapping("/user/yxsy/list.go")
	public String toYxsyDetails(HttpServletRequest request) {
		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 13.放入优选摄影
		List<Yxsy> yxsys = yxsyService.getAllYxhz();
		request.setAttribute("yxsys", yxsys);

		return "user/photo-list";
	}

	// 婚庆的第三层详情页
	@RequestMapping("/user/yxhqwp/{id}.go")
	public String toYxhqWP(@PathVariable("id") Integer id, HttpServletRequest request) {
		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 把跳转之前的路径设置到页面，留给后续返回用
		String url = request.getHeader("Referer");
		request.setAttribute("url", url);

		// 婚庆工作集对应的id的图片
		Yxhq_work_picture yxhqWPD = yxhqWorkPictureService.selectById(id);
		request.setAttribute("yxhqWPD", yxhqWPD);

		return "user/wed-oups-detail";
	}

	// 化妆师的第三层详情页
	@RequestMapping("/user/yxhzwp/{id}.go")
	public String toYxhzWP(@PathVariable("id") Integer id, HttpServletRequest request) {
		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 把跳转之前的路径设置到页面，留给后续返回用
		String url = request.getHeader("Referer");
		request.setAttribute("url", url);

		// 化妆工作集对应的id的图片
		Yxhz_work_picture yxhzWPD = yxhzWorkPictureService.selectById(id);
		request.setAttribute("yxhzWPD", yxhzWPD);

		return "user/wed-oups-detail";
	}

	// 摄影师的第三层详情页
	@RequestMapping("/user/yxsywp/{id}.go")
	public String toYxsyWP(@PathVariable("id") Integer id, HttpServletRequest request) {
		// 1.放入广告图
		List<Advertisement_picture> advers = advertisementSservice.selectAllAdvers();
		request.setAttribute("advers", advers);

		// 把跳转之前的路径设置到页面，留给后续返回用
		String url = request.getHeader("Referer");
		request.setAttribute("url", url);

		// 摄影师工作集对应的id的图片
		Yxsy_work_picture yxsyWPD = yxsyWorkPictureService.selectById(id);
		request.setAttribute("yxsyWPD", yxsyWPD);

		return "user/photo-oups-detail";
	}
}
